<template>
    <van-icon
      :color="value === 1 ? 'red' : '#777'"
      :name="value === 1 ? 'good-job' : 'good-job-o'"
      @click="onLike"
    />
</template>

<script>
import { addLikeUser, removeLikeUser } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    value: {
      type: Number,
      required: true
    },
    artId: {
      type: [Number, Object],
      require: true
    }
  },
  data () {
    return {

    }
  },

  created () {

  },

  methods: {
    async onLike () {
      try {
        if (this.value === 1) {
          await removeLikeUser(this.artId)
          Toast.success('取消点赞')
        } else {
          await addLikeUser(this.artId)
          Toast.success('点赞成功')
        }
        this.$emit('input', -this.value)
      } catch (error) {
        Toast.fail('操作失败')
      }
    }
  }
}
</script>

<style scoped>

</style>
